<template>
	<view>
		<view class="tui-tabs">
			<scroll-view id="tab-bar" scroll-with-animation class="tui-scroll-h" :scroll-x="true"
				:show-scrollbar="false" style="border-bottom: 2upx solid #F8F8F8;height: 90upx;">
				<view style="display: flex;">
					<view v-for="(tab, index) in SecKillTime" :id="tab.secKillTimeId" :data-current="index"
						@tap='tabSlect(tab)'>
						<view class="tui-tab-item-title"
							style="margin-left: 50upx;margin-right: 20upx;display: flex;flex-direction: column;"
							:class="{ 'tui-tab-item-title-active': tabIndex == tab.secKillTimeId }">
							{{ tab.startHour }}:00
							<view>{{tab.status}}</view>

						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- #ifdef H5 -->
		<view style="display: flex;flex-wrap: wrap;margin-top: 80upx;">
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<view style="display: flex;flex-wrap: wrap;margin-top: 20rpx;">
				<!-- #endif -->
				<!-- #ifdef APP-PLUS -->
				<view style="display: flex;flex-wrap: wrap;">
					<!-- #endif -->
					<view
						style="width: 345upx;height: 510upx;background-color: #FFFFFF; border-radius: 20upx;margin-left: 20upx; margin-top: 20upx;box-shadow: rgba(183, 183, 183, 0.3) 1px 1px 10px 1px;"
						@tap='goDetail(item.secKillId)' v-for="(item,index) in list" :key='index'>
						<image :src="item.coverImg"
							style="width: 345upx;height: 340upx;border-top-left-radius:20upx;border-top-right-radius:20upx;">
						</image>
						<view style="padding: 16upx 2upx 16upx 16upx;">
							<view style="width: 100%;height:  60upx;">
								<text class="limapboxqing2"><text class="indexr"
										style=""><text>秒杀</text></text>{{ item.title }}</text>
							</view>
						</view>
						<view style="padding: 0rpx 15rpx;display: flex;margin:20rpx 0">
							<view v-if="relation"
								style="width: 40%;font-size: 38upx;color: #FF2A47;font-weight: 700;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
								<text style="font-size: 26rpx;">¥</text>{{item.memberPrice}}</view>
							<view v-if='!relation'
								style="width: 40%;font-size: 38upx;color: #FF2A47;font-weight: 700;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
								<text style="font-size: 26rpx;">¥</text>{{item.price}}</view>
							<view
								style="width: 60%;font-size: 24upx;color: #999999;margin-top: 8upx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;text-align: right;">
								{{item.goods.sales}}人已购买</view>
						</view>
					</view>

					<!-- 悬浮上拉 -->
					<view class="scroll_top" @tap="topScrollTap" v-bind:class="[scrollTop ? 'active' : '','']"
						style="bottom: 56px;">
						<text class="iconfont icon-shangla"></text>
					</view>

					<!-- 加载更多提示 -->
					<view class="s-col is-col-24" v-if="list.length > 0">
						<load-more :loadingType="loadingType" :contentText="contentText"></load-more>
					</view>
					<!-- 加载更多提示 -->
					<!-- #ifdef APP-PLUS -->
					<empty v-if="list.length === 0" des="暂无商品数据" show="false" style="margin-top: 80rpx;"></empty>
					<!-- #endif -->
					<!-- #ifndef APP-PLUS -->
					<empty v-if="list.length === 0" des="暂无商品数据" show="false"></empty>
					<!-- #endif -->
				</view>
			</view>
</template>

<script>
	export default {
		data() {
			return {
				tabIndex: '1',
				list: [],
				SecKillTime: [],
				relation: false,
				page: 0,
				isEnable: '否',
				scrollLeft: 0,
				size: 10,
				tabStatus: '',
				loadingType: 0,
				type: 1,
				scrollTop: false,
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				}
			}
		},
		onShow() {
			let a = this.$queue.getData('isEnable');
			if (a === '是') {
				let b = this.$queue.getData('isLieBiaoEnable');
				if (b) {
					this.isEnable = b;
				} else {
					this.isEnable = a;
				}
			} else {
				this.isEnable = a;
			}
		},
		onLoad(d) {
			let relation_id = this.$queue.getData('relation_id');
			if (relation_id && relation_id !== 'undefined') {
				this.relation = true;
			} else {
				this.relation = false;
			}
			this.getallList();
		},
		methods: {
			goDetail(id) {
				if (this.tabStatus === '抢购中') {
					uni.navigateTo({
						url: './commoditydetail?className=miaosha&ordersId=' + id
					});
				}
			},
			getSeckillUserList(type, secKillTimeId) {
				this.loadingType = 1;
				uni.showLoading({
					title: '加载中...'
				});
				this.$Request.getT('/selfSecKill/userList?page=' + this.page + '&size=' + this.size + '&secKillTimeId=' +
					secKillTimeId).then(res => {
					if (res.status === 0) {
						if (this.page === 0 || res.status) {
							this.list = [];
						}
						let grade = this.$queue.getData('grade');
						res.data.content.forEach(d => {
							d.descrition = '';
							if (d.commissionPrice != 0) {
								if (grade) {
									if (this.relation) {
										d.descrition = ((parseFloat(d.memberPrice) * parseFloat(d
											.commissionPrice)) * parseFloat(grade)).toFixed(
											2);
									} else {
										d.descrition = ((parseFloat(d.price) * parseFloat(d
											.commissionPrice)) * parseFloat(grade)).toFixed(2);
									}
								} else {
									if (this.relation) {
										d.descrition = ((parseFloat(d.memberPrice) * parseFloat(d
													.commissionPrice)) * parseFloat(this.$queue
											.minMoney()))
											.toFixed(2);
									} else {
										d.descrition = ((parseFloat(d.price) * parseFloat(d
													.commissionPrice)) * parseFloat(this.$queue
											.minMoney()))
											.toFixed(2);
									}
								}
							}
							d.sales = d.sales > 10000 ? (d.sales / 10000).toFixed(1) + '万' : d.sales;
							this.list.push(d);
						});
						if (res.data.content.length === this.size) {
							this.loadingType = 0;
						} else {
							this.loadingType = 3;
						}
					} else {
						this.loadingType = 2;
					}
					uni.hideLoading();
					if (type === 'Refresh') {
						uni.stopPullDownRefresh(); // 停止刷新
					}
				});
			},
			getallList() {
				this.$Request.getT('/selfSecKillTime/allList').then(res => {
					if (res.status === 0) {
						for (var i = 0; i < res.data.length; i++) {
							if (res.data[i].status > 1) {
								if (res.data[i].status === 2) {
									this.tabIndex = res.data[i].secKillTimeId;
									res.data[i].status = '抢购中';
									this.getSeckillUserList('', this.tabIndex);
									this.tabStatus = '抢购中';
								} else if (res.data[i].status === 3) {
									res.data[i].status = '即将开始';
								}
								this.SecKillTime.push(res.data[i]);
							}
						}
					}
				});
			},
			tabSlect(item) {
				this.tabStatus = item.status
				this.switchTab(item.secKillTimeId);
			},
			switchTab(index) {
				this.page = 0;
				this.tabIndex = index;
				this.scrollLeft = (index - 1) * 50;
				this.list = [];
				this.getSeckillUserList('switch', index);
			},
			topScrollTap: function() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			}
		},
		onPageScroll: function(e) {
			this.scrollTop = e.scrollTop > 200;
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getSeckillUserList('', this.tabIndex);
		},
		onPullDownRefresh: function() {
			this.page = 0;
			this.getSeckillUserList('Refresh', this.tabIndex);
		}
	}
</script>

<style lang="less" scoped>
	@import '../../../static/less/index.less';
	@import '../../../static/css/index.css';

	page {
		background: #F8F8F8;
	}

	.tui-tabs {
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		background-color: #fafafa;
		/* #ifdef MP-ALIPAY || MP-BAIDU */
		height: 100vh;
		/* #endif */
	}

	.indexr {
		color: #FFFFFF;
		font-size: 22upx;
		padding-left: 12upx;
		display: inline-block;
		padding-right: 13upx;
		border-radius: 8upx;
		margin-right: 8upx;
		padding-top: 4upx;
		line-height: 38upx;

		background: -moz-linear-gradient(left, #FB2C1A 0, #FF2A46 100%);
		background: -webkit-gradient(linear, left top, left right, color-stop(0, #FB2C1A), color-stop(100%, #FF2A46));
		background: -webkit-linear-gradient(left, #FB2C1A 0, #FF2A46 100%);
		background: -o-linear-gradient(left, #FB2C1A 0, #FF2A46 100%);
		background: -ms-linear-gradient(left, #FB2C1A 0, #FF2A46 100%);
		background: linear-gradient(to left, #FB2C1A 0, #FF2A46 100%);
	}

	.tui-scroll-h {
		width: 750rpx;
		height: 79rpx;
		background-color: #ffffff;
		flex-direction: row;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
		/* #ifdef H5 */
		position: fixed;
		top: 44px;
		left: 0;
		z-index: 999;
		/* #endif */
	}

	.tui-line-h {
		/* #ifdef APP-PLUS */
		height: 1rpx;
		background-color: #cccccc;
		/* #endif */
		position: relative;
	}

	/* #ifndef APP-PLUS*/
	.tui-line-h::after {
		content: '';
		position: absolute;
		border-bottom: 1rpx solid #cccccc;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		bottom: 0;
		right: 0;
		left: 0;
	}

	/* #endif */

	.tui-tab-item {
		/* #ifndef APP-PLUS */
		display: flex;
		/* #endif */
	}

	.tui-tab-item-title {
		color: #555;
		font-size: 30rpx;
		height: 80rpx;
		line-height: 40rpx;
		flex-wrap: nowrap;
		text-align: center;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	.tui-tab-item-title-active {
		color: #E10A07;
		font-size: 32upx;
		font-weight: bold;
		border-bottom-width: 5upx;
		text-align: center;
	}

	.limapboxqing2 {

		font-size: 28upx;
		color: #333333;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
</style>
